<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/6/20
  Time: 9:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<jsp:include page="/_meta.jsp"/>
<link href="/lib/easyui/themes/default/easyui.css" rel="stylesheet" type="text/css">
<link href="/lib/easyui/themes/icon.css" rel="stylesheet" type="text/css">
<title>出库单</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 库存管理 <span
        class="c-gray en">&gt;</span> 库存上下限设置 <a class="btn btn-success radius r"
                                                 style="line-height:1.6em;margin-top:3px"
                                                 href="javascript:location.replace(location.href);" title="刷新"><i
        class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container form" style="width:1000px;margin:20px auto">
    <div class="row cl ">
        <label class="form-label col-xs-4 mylabel sto"><span class="c-red">*</span>仓库</label>
        <div class="formControls col-xs-8 col-sm-9 ">
            <input id="sto" class="sto input-text" type="text">
        </div>
    </div>
    <div class="row cl">
        <label class="form-label col-xs-4 mylabel proBarCode"><span class="c-red">*</span>商品条码</label>
        <div class="formControls col-xs-8 col-sm-9">
            <input id="proBarCode" class="easyui-combobox input-text"
                   data-options="valueField:'proBarCode',textField:'proName',width:300" type="text">
        </div>
    </div>
    <div class="row cl">
        <label class="form-label col-xs-4 mylabel topNum"><span class="c-red">*</span>上限</label>
        <div class="formControls col-xs-8 col-sm-9">
            <input id="topNum" class="easyui-numberbox input-text" data-options="width:300" type="text">
        </div>
    </div>
    <div class="row cl">
        <label class="form-label col-xs-4 mylabel buttNum"><span class="c-red">*</span>下限</label>
        <div class="formControls col-xs-8 col-sm-9">
            <input id="buttNum" class="easyui-numberbox input-text" data-options="width:300" type="text">
        </div>
    </div>
    <div class="row cl">
        <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
            <input class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;设置&nbsp;&nbsp;">
        </div>
    </div>
</div>
<jsp:include page="/_footer.jsp"/>
<script src="/lib/easyui/jquery.easyui.min.js"></script>
<script src="/lib/easyui/locale/easyui-lang-zh_CN.js"></script>
<script>
    var stoData;
    var empData;
    $(function () {
        $.post("/GetAllStorServlet", {ajax: "comb"}, function (data) {
            stoData = $.parseJSON(data);
            $("#sto").combobox({
                data: stoData,
                width: 300,
                valueField: 'id',
                textField: 'text',
                filter: combFilter,
                onSelect: function (target) {
                    $.post("/GetDefaultStoInvServlet", {stoId: target.id}, function (data) {
                        var barCode = [];
                        var jjdata = $.parseJSON(data);
                        for (var i = 0; i < jjdata.length; i++) {
                            barCode[i] = {
                                proBarCode: jjdata[i].product.proBarCode,
                                proName: jjdata[i].product.proName + "[" + jjdata[i].product.proBarCode + "]"
                            };
                        }
                        $("#proBarCode").combobox({
                            data: barCode,
                            width: 300,
                            valueField: 'proBarCode',
                            textField: 'proName',
                            filter: combFilter,
                            onSelect: function (tar) {
                                for (var i = 0; i < jjdata.length; i++) {
                                    if (jjdata[i].product.proBarCode == tar.proBarCode) {
                                        $("#topNum").numberbox('setValue', jjdata[i].invTopNum);
                                        $("#buttNum").numberbox('setValue', jjdata[i].invBottNum);
                                        break;
                                    }
                                }
                            }
                        })
                    });
                }
            });
        });
    });
    $(".btn").click(function () {
        var o = $("#sto").val();
        if (o == "") {
            layer.tips("仓库必须选择", ".sto");
            return;
        }
        var proBarCode = $("#proBarCode").val();
        if (proBarCode == "") {
            layer.tips("商品必须选择", ".proBarCode");
            return;
        }
        var topNum = $("#topNum").val();
        if (!topNum.match(/^[0-9]+$/)) {
            layer.tips("上限必须是数字", ".topNum");
            return;
        }
        if(parseInt(topNum)<=0){
            layer.tips("必须大于0！", ".topNum");
            return;
        }
        var buttNum=$("#buttNum").val();
        if (!buttNum.match(/^[0-9]+$/)) {
            layer.tips("下限必须是数字", ".buttNum");
            return;
        };
        if(parseInt(buttNum)<=0){
            layer.tips("必须大于0！", ".buttNum");
            return;
        }
        var param = {
            sto: o,
            topNum:topNum,
            buttNum:buttNum,
            proBarCode: proBarCode,
        };
        $.post("/SetInvLimitServlet", param, function (data) {
            if (data == "true") {
                layer.msg("设置成功！");
            }
            else {
                layer.msg("设置失败！");
            }
        });
    });
    function combFilter(q, row) {
        var opts = $(this).combobox('options');
        return row[opts.textField].indexOf(q) >= 0;//带输入的下拉框本地检索
    }
</script>
